<template>
	<view class="wrap">
		<block v-if="dataBuffer">
			<view class="top">
				<image :src="bannerimg" mode="widthFix" class="topBanner"></image>
				<image src="../../static/active.png" mode="widthFix" class="bottomBanner"></image>
			</view>
			<u-waterfall v-model="flowList" ref="uWaterfall">
				<template v-slot:left="{leftList}">
					<view class="demo-warter" v-for="(item, index) in leftList" :key="index">
						<!-- 警告：微信小程序中需要hx2.8.11版本才支持在template中结合其他组件，比如下方的lazy-load组件 -->
						<!-- <u-lazy-load threshold="-450" border-radius="10" :image="item.image" :index="index"></u-lazy-load> -->
						<!-- <u-lazy-load threshold="-450" border-radius="10" :image="item.image" :index="index"></u-lazy-load> -->
						<image :src="item.img" :lazy-load="true" style="width: 100%;height: 150px;"></image>
						<view class="demo-title">
							{{item.goodsname}}
						</view>
						<view class="demo-price">
							{{item.price}}元
						</view>
						<view class="demo-tag">
							<view class="demo-tag-owner">
								自营
							</view>
							<view class="demo-tag-text">
								放心购
							</view>
						</view>
						<view class="demo-shop">
							U选
						</view>
						<u-icon name="close-circle-fill" color="#fa3534" size="34" class="u-close" @click="remove(item.id)"></u-icon>
					</view>
				</template>
				<template v-slot:right="{rightList}">
					<view class="demo-warter" v-for="(item, index) in rightList" :key="index">
						<!-- <u-lazy-load threshold="-450" border-radius="10" :image="item.image" :index="index"></u-lazy-load> -->
						<!-- <u-lazy-load threshold="-450" border-radius="10" :image="item.image" :index="index"></u-lazy-load> -->
						<image :src="item.img" :lazy-load="true" style="width: 100%;height: 145px;"></image>
						<view class="demo-title">
							{{item.goodsname}}
						</view>
						<view class="demo-price">
							{{item.price}}元
						</view>
						<view class="demo-tag">
							<view class="demo-tag-owner">
								自营
							</view>
							<view class="demo-tag-text">
								放心购
							</view>
						</view>
						<view class="demo-shop">
							U选
						</view>
						<u-icon name="close-circle-fill" color="#fa3534" size="34" class="u-close" @click="remove(item.id)"></u-icon>
					</view>
				</template>
			</u-waterfall>
			<u-loadmore bg-color="rgb(240, 240, 240)" :status="loadStatus" @loadmore="addRandomData"></u-loadmore>
		</block>
		<!-- 无数据提示 -->
		<u-empty 
			text="暂无数据~~去逛逛~~" mode="list" 
			:show="!dataBuffer" 
			color="orange" icon-color="orange"
		></u-empty>
	</view>
</template>

<script>
	// 引入测试数据 可以测试使用
	// import list from '@/utils/active.data.js'
	export default {
		data() {
			return {
				loadStatus: 'loadmore',
				flowList: [],
				totalPage:0,
				dataBuffer:true,
				bannerimg:"",//活动图片
				page:1,
				size:6,
				baseUrl:this.$URL,
			}
		},
		onLoad(option){
			// this.flowList = list;
			// 1.获取参数
			let params =  JSON.parse(option.params)
			console.log(params)
			// 2.动态设置标题
			uni.setNavigationBarTitle({
				title:params.title
			})
			this.bannerimg = params.img;
			this.cateid = params.second_cateid
			// 3.获取数据
			this.getGoods()
		},
		onReachBottom() {
			this.page++;
			// 当当前访问的页码大于总页码，显示没有更多数据
			if(this.page > this.totalPage){
				this.loadStatus = "nomore"
				return;
			}
			// 正常加载，显示加载中
			this.loadStatus = "loading";
			this.getGoods()
		},
		methods: {
			// 1.获取数据
			async  getGoods(){
				let {page,size,cateid} = this;
				var option = {
					url:"getgoodlist",
					data:{
						type:2,
						page,
						size,
						cateid,
					}
				}
				var res =  await  this.$http(option);
				console.log(res,123)
				if(res.data.list.goodData == null){
					// 没有活动
					this.dataBuffer = false;
				}else{
					// 有活动
					this.dataBuffer = true;
					res.data.list.goodData.map((item,index)=>{
						item.img =  this.$URL + item.img
					})
					this.flowList = this.flowList.concat(res.data.list.goodData);
					this.totalPage = res.data.list.totalPage;
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	// 引入样式
	@import '@/static/css/active.scss'
</style>
